<template>
  <div>
    <div class="logo">
      <div class="logo-in">
        <img src="~assets/images/logo.png" alt="">
      </div>
    </div>
    <ul class="asideMenu">
      <li v-for="(item, index) in menuList" :class="item.isSubShow? 'bottom-border': ''">
        <div :class="item.isSubShow? 'oneMenu is-active': 'oneMenu'" @click="showToggle(item, index)">
          <div class="aside-left">
            <i :class="['iconfont', item.icon]"></i>
            <span>{{item.name}}</span>
          </div>
          <div v-if="item.children.length>0" class="iconfont icon-jiantou jiantou"></div>
        </div>
        <ul v-show="item.isSubShow">
          <router-link tag="li" v-for="subItem in item.children" :to="subItem.to">
            <b :class="['iconfont', subItem.icon]"></b>
            <div class="oneMenuChild">{{subItem.name}}</div>
          </router-link>
        </ul>
      </li>
    </ul>
  </div>

</template>

<script>
  export default {
    name: "AsideBar",
    data() {
      return {
        // menuList: [{
        //   name: '首页',
        //   isSubShow: true,
        //   icon: 'icon-shouye',
        //   children: [{
        //     name: '数据统计',
        //     icon: 'icon-tongji',
        //     to: '/dashboard/home'
        //   }]
        // }, {
        //   name: '文章管理',
        //   isSubShow: false,
        //   icon: 'icon-16',
        //   children: [{
        //     name: '文章列表',
        //     icon: 'icon-combinedshapecopy2',
        //     to: '/dashboard/article'
        //   }, {
        //     name: '分类列表',
        //     icon: 'icon-fenlei',
        //     to: '/dashboard/category'
        //   }, {
        //     name: '标签列表',
        //     icon: 'icon-biaoqian',
        //     to: '/dashboard/tag'
        //   }]
        // }, {
        //   name: '网站管理',
        //   isSubShow: false,
        //   icon: 'icon-diannao01',
        //   children: [{
        //     name: '评论管理',
        //     icon: 'icon-pinglun',
        //     to: '/dashboard/comment'
        //   }, {
        //     name: '公告管理',
        //     icon: 'icon-gonggao',
        //     to: '/dashboard/notice'
        //   }, {
        //     name: '轮播图管理',
        //     icon: 'icon-tupian',
        //     to: '/dashboard/carousel'
        //   }]
        // }, {
        //   name: '用户管理',
        //   isSubShow: false,
        //   icon: 'icon-wode',
        //   children: [{
        //     name: '用户列表',
        //     icon: 'icon-yonghuguanli',
        //     to: '/dashboard/user'
        //   }, {
        //     name: '角色管理',
        //     icon: 'icon-icon-test',
        //     to: '/dashboard/role'
        //   }]
        // }]
        menuList: this.$store.state.currentUser.permission.menuList
      }
    },

    methods:{
      // 点击展开折叠菜单事件
      showToggle(item, index) {
        let currentPath = this.$route.path;
        if (item.to != null && item.to != currentPath) {
          // 一级菜单直接跳转
          this.$router.push(item.to);
          // 判断如果数据中的menuList[i]的show属性不等于当前数据的isSubShow属性那么menuList[i]等于false
          this.menuList.forEach(i => {
            if (i.isSubShow !== this.menuList[index].isSubShow) {
              i.isSubShow = false;
            }
          });
          item.isSubShow = !item.isSubShow;
        } else {
          // 二级菜单展示
          this.menuList.forEach(i => {
            // 判断如果数据中的menuList[i]的show属性不等于当前数据的isSubShow属性那么menuList[i]等于false
            if (i.isSubShow !== this.menuList[index].isSubShow) {
              i.isSubShow = false
            }
          });
          item.isSubShow = !item.isSubShow;
        }
      },
    }
  }
</script>

<style scoped>
  @import "~assets/fonts/iconfont.css";

  .logo {
    width: 200px;
    height: 100px;
    transition: all 300ms;
  }
  .logo-in {
    width: 180px;
    height: 100%;
    margin: 0 auto;
    border-bottom: 1px solid #ccc;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
  }
  img {
    width: 180px;
    height: 60px;
    margin-top: 20px;
  }
  .asideMenu {
    background: url("~assets/images/bolang-aside.png") no-repeat bottom center;
    background-size: 300px;
    padding-top: 20px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    height: calc(100% - 100px);
    transition: all 300ms;
  }

  .asideMenu>li {
    width: 100%;
    /*line-height: 50px;*/
    color: #fff;
    font-size: 14px;
    letter-spacing: 1px;
    cursor: pointer;
    /*border: 1px solid #fff;*/
    transition: all 300ms;
    box-sizing: border-box;
  }

  .asideMenu>li>div {
    height: 50px;
    line-height: 50px;
  }

  .bottom-border {
    border-bottom: 1px solid #e0e0e0;
  }
  .asideMenu>li:first-child {
    border-bottom: none
  }
  .asideMenu>li>.is-active {
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
    position: relative;
  }

  .asideMenu>li i {
    margin-left: 20px;
    margin-right: 10px;
    font-weight: normal;
    vertical-align: bottom;
  }
  .asideMenu>li>div {
    display: flex;
    justify-content: space-between;
  }
  .asideMenu>li .jiantou {
    display: inline-block;
    margin-right: 10px;
    vertical-align: bottom;
  }
  .asideMenu>li>.is-active .jiantou {
    transform: rotateZ(90deg);
  }
  .asideMenu>li>ul {
    list-style: none;
    transition: all 300ms;
  }

  .asideMenu>li>ul b {
    margin-left: 40px;
    font-weight: normal;
    display: inline-block;
    margin-right: 10px;

  }
  .asideMenu>li>ul .oneMenuChild {
    display: inline-block;
    transition: all 300ms;
    height: 50px;
    line-height: 50px;
  }

  .aside-left {
    display: inline-block;
  }

  .router-link-active {
    color: #6d7ee9;
    background-color: #fff;
    border-bottom: 1px solid #eee;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
  }

</style>


<style lang="scss" scoped>

</style>
